#!/bin/sh

# MQTT Firmware test

# Check for application
[ ! -x ./examples/firmware/fwpush ] && echo -e "\n\nMQTT Example fwpush doesn't exist" && exit 1
[ ! -x ./examples/firmware/fwclient ] && echo -e "\n\nMQTT Example fwclient doesn't exist" && exit 1

def_args="-t -T -C 5000"
filein=./README.md
fileout=./README.md.trs

# Start firmware push
./examples/firmware/fwpush $def_args -r -f $filein $1
server_result=$?
[ $server_result -ne 0 ] && echo -e "\n\nMQTT Example fwpush failed!" && exit 1

# Start firmware client
./examples/firmware/fwclient $def_args -f $fileout $1
client_result=$?
[ $client_result -ne 0 ] && echo -e "\n\nMQTT Example fwclient failed!" && exit 1

# Compare files
md5sum -b $filein $fileout
compare_result=$?
[ $client_result -ne 0 ] && echo -e "\n\nMQTT Example firmware compare failed!" && exit 1

# Delete file
rm $fileout

echo -e "\n\nFirmware Example MQTT Client Tests Passed"

exit 0
